using EnvDTE;
using Microsoft.Practices.RecipeFramework;
using VSSDKAssist.Assets.Actions.Base;

namespace VSSDKAssist.Assets.Actions.VisualStudio
{
	/// <summary>
	/// Action that deletes a project item
	/// </summary>
	public class DeleteItemIfExistsFromProjectAction : ActionBase
    {
        #region Input Properties

        private string itemName;

		/// <summary>
		/// Gets or sets the name of the item.
		/// </summary>
		/// <value>The name of the item.</value>
        [Input(Required=true)]
        public string ItemName
        {
            get { return itemName; }
            set { itemName = value; }
        }

        private Project project;

		/// <summary>
		/// Gets or sets the project.
		/// </summary>
		/// <value>The project.</value>
        [Input(Required=true)]
        public Project Project
        {
            get { return project; }
            set { project = value; }
        }
        #endregion

		/// <summary>
		/// Called when [execute].
		/// </summary>
		protected override void OnExecute()
		{
            foreach(ProjectItem item in Project.ProjectItems)
            {
                if(item.Name.Equals(itemName))
                {
                    item.Delete();
                    break;
                }
            }
        }
    }
}
